<template>
    <div class="login-container">
        <div class="login-box">
            <h1 class="title">互联网医疗服务后台管理</h1>
            <div class="login-form">
                <div class="form-item">
                    <i class="icon user-icon"></i>
                    <input type="text" v-model="loginForm.UserName" placeholder="请输入用户名" />
                </div>
                <div class="form-item">
                    <i class="icon password-icon"></i>
                    <input type="password" v-model="loginForm.Password" placeholder="请输入密码" showpassword />
                </div>
                <button class="login-button" @click="handleLogin">登录</button>
            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import axios from 'axios'
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router'
const router = useRouter()

const loginForm = ref({
    UserName: '',
    Password: '',
});

const handleLogin = () => {

    axios.get('http://47.95.68.41:4570/api/RBAC/Login', { params: loginForm.value })
        .then(res => {
            // 处理登录成功后的逻辑
            console.log(res.data);

            if (res.data.code == 200) {

                ElMessage.success('登录成功');
                router.push('/home')
            }
            else {


                ElMessage.error(res.data.msg);
            }

        })
        .catch(error => {
            // 处理登录失败后的逻辑
            console.error(error);
        });



}

</script>

<style scoped>
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #2d8cf0;
}

.login-box {
    width: 400px;
    padding: 40px;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.title {
    text-align: center;
    margin-bottom: 40px;
    font-size: 24px;
    color: #333;
}

.form-item {
    position: relative;
    margin-bottom: 20px;
}

.icon {
    position: absolute;
    left: 10px;
    top: 12px;
    width: 16px;
    height: 16px;
    background-size: contain;
}

.user-icon {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23bfbfbf"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>');
}

.password-icon {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23bfbfbf"><path d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z"/></svg>');
}

input {
    width: 100%;
    height: 40px;
    padding: 0 15px 0 35px;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 14px;
    color: #606266;
}

input:focus {
    outline: none;
    border-color: #409eff;
}

.login-button {
    width: 100%;
    height: 40px;
    background-color: #2d8cf0;
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 16px;
    cursor: pointer;
    margin-top: 10px;
}

.login-button:hover {
    background-color: #2a80d8;
}
</style>